package cn.flying.cloud.sso.server.configuration.token;

import javax.annotation.Resource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * token相关配置
 *
 * @author: admin
 * @date: 2023年06月20日 10:43
 * @version: 1.0
 */
@Configuration
public class TokenConfig {
    private static final String SIGN_KEY = "123";

    @Resource
    private RedisConnectionFactory redisConnectionFactory;

//    @Bean
//    public TokenStore tokenStore() {
////        return new JdbcTokenStore(dataSource);
//        return new RedisTokenStore(redisConnectionFactory);
//    }


    @Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter();
        //配置JWT使用的秘钥
        accessTokenConverter.setSigningKey(SIGN_KEY);
        return accessTokenConverter;
    }
}